<!DOCTYPE HTML>
<script type="module">
import {ACCEPTABLE_CREDENTIAL, ACCEPTABLE_CREDENTIAL_ID, CHALLENGE} from './test-inputs.js';
import {TestAuthenticatorManager} from './virtual-navigator-credentials.js';

let queryParams = new URLSearchParams(window.location.search);
var relyingPartyId = queryParams.has('rpId') ? queryParams.get('rpId') : document.domain;
var getCredentialOptions = {
    challenge: CHALLENGE,
    rpId: relyingPartyId,
    allowCredentials: [ACCEPTABLE_CREDENTIAL],
    userVerification: 'discouraged',
};
let responder =  window.opener || window.parent;

const manager = new TestAuthenticatorManager;
manager.createAuthenticator().then((testAuthenticator) => {
  return testAuthenticator.generateAndRegisterKey(ACCEPTABLE_CREDENTIAL_ID, relyingPartyId).then(() => {
    return navigator.credentials.get({publicKey : getCredentialOptions});
  });
}).then(r => responder.postMessage("SUCCESS", "*"))
  .catch(t => responder.postMessage(t.name, "*"));

</script>
